import time
from typing import List


def func(_time_list1: List[str], _time_list2: List[str], _meet_time: int):
    result = []
    possible_time1, possible_time2 = [], []

    for x in _time_list1:
        _start, _end = x.split(",")
        if get_minutes(_start, _end) >= _meet_time:
            possible_time1.append([_start, _end])
    for y in _time_list2:
        _start, _end = y.split(",")
        if get_minutes(_start, _end) >= _meet_time:
            possible_time2.append([_start, _end])

    for z in possible_time1:
        for m in possible_time2:
            if get_same(z, m) >= _meet_time:
                return get_final(z, m, _meet_time)
    return result


def get_final(_t1, _t2, _meet_t):
    start = max(_t1[0], _t2[0])
    h1, m1 = list(map(int, start.split(":")))
    h2, m2 = meet_time//60, meet_time % 60
    if (m1 + m2) >= 60:
        h = h1 + h2 + 1
        m = m1 + m2 - 60
    else:
        h = h1 + h2
        m = m1 + m2
    if m < 10:
        m = "0" + str(m)
    return "[" + start + ", " + str(h) + ":" + m + "]"


def get_same(_time1, _time2) -> int:
    _count = 0
    if (_time1[0] <= _time2[0]) and (_time2[0] < _time1[1]):
        _count = get_minutes(_time2[0], min(_time1[1], _time2[1]))
    if (_time2[0] <= _time1[0]) and (_time1[0] < _time2[1]):
        _count = get_minutes(_time1[0], min(_time1[1], _time2[1]))
    return _count


def get_minutes(_time1: str, _time2: str) -> int:
    total = 0
    h1, m1 = list(map(int, _time1.split(":")))
    h2, m2 = list(map(int, _time2.split(":")))
    total = (h2 - h1) * 60 + (m2 - m1)
    return total


if __name__ == '__main__':
    time1 = input().strip().split(";")
    time2 = input().strip().split(";")
    meet_time = int(input().strip())

    print(str(func(time1, time2, meet_time)))
